package model

import (
	"gorm.io/gorm"
	"time"
	"wechat_1004/global"
)

type Friend struct {
	Id        uint32         `gorm:"column:id;type:int UNSIGNED;comment:id;primaryKey;not null;" json:"id"` // id
	UserId    int32          `gorm:"column:user_id;type:int;comment:用户ID;not null;" json:"user_id"`         // 用户ID
	FriendId  int32          `gorm:"column:friend_id;type:int;comment:联系人ID;not null;" json:"friend_id"`    // 联系人ID
	Name      string         `gorm:"column:name;type:varchar(30);comment:备注;default:NULL;" json:"name"`     // 备注
	Status    int8           `gorm:"column:status;type:tinyint(1);not null;" json:"status"`
	CreatedAt time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (f *Friend) TableName() string {
	return "friend"
}

// 添加
func (f *Friend) AddFriend() error {
	return global.DB.Create(&f).Error
}

// 同步通讯录
func (f *Friend) FindFriend() (list []Friend, err error) {
	err = global.DB.Where("user_id = ?", f.UserId).Find(&list).Error
	return
}
